﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.OracleClient;

namespace OracleDAL.ElecBoss
{
    public class Fault
    {
       
        public int addFault(string sqlStr)
        {
            return DBUtility.OracleHelper.ExecuteSql(sqlStr);
        }
        public DataSet getFault(string whereSql)
        {
          //  string strSql = "select id,ftype,name,tel,unit,fstate,to_date(reporttime,'YYYY-MM-DD HH24:MI:SS') as reporttime,fcontent,clmind,clr,to_date(cltime,'YYYY-MM-DD HH24:MI:SS') as cltime,to_date(completetime,'YYYY-MM-DD HH24:MI:SS') as completetime,ip from fault ";
            DataSet ds = new DataSet();
            string strSql = "select distinct f.id,f.ftype,f.name,v.id as eid,f.EQUIPTYPE,f.equipname,f.tel,f.unit,f.fstate,f.reporttime,f.fcontent,f.clmind,f.clr,f.cltime,f.completetime,f.ip,f.isticket,f.alarmcase,f.happentime,f.clrtel,f.VENDOR,f.faultLevel from fault f,V_ALARMOBJECT  v";
            strSql += " where v.id=f.equipmentid and " + whereSql + "  ";
            ds = DBUtility.OracleHelper.Query(strSql);
            return ds;
        }
        public DataSet getFaultToDuty(string where)
        {
            string sql = "";
            if (where == "")
            {
                sql = "select count(*) from fault where fstate='已派发' union all select count(*) from fault where fstate='未处理' union all select count(*) from fault where fstate='已完成'";
            }
            else
            {
                sql = "select id,ftype,name,tel,unit,fstate,reporttime,fcontent,clmind,clr,cltime,completetime,ip from fault ";
                sql += " where " + where + "";
            }
            DataSet ds = new DataSet();
            ds = DBUtility.OracleHelper.Query(sql);
            return ds;

        }
        public DataSet getTempDs()
        {
            DataSet ds = new DataSet();
            string sql = "select * from duty_info";
            ds = DBUtility.OracleHelper.Query(sql);
            return ds;
        }
        public DataSet getAlarm(string where)
        {
            DataSet ds = new DataSet();
            string strSql = "SELECT distinct ai.alarmnumber,v.name as alarmobject,v.id,ar.resourcecnname as objclass ,ai.alarmtext,";
            strSql += "ai.alarmtype,ai.alarmdesc,ai.belongdomain,ai.vendor,";
            strSql += "ai.probablecause,ai.alarmlevel,ai.iscleared,ai.vendor,ai.starttime,ai.endtime,ai.isticket  ";
            strSql += " FROM alarm_info ai,v_alarmobject v,alarm_resource ar where ai.objclass = ar.resourcecnname  and v.id=ai.alarmobject and ai.endtime is null and " + where + "   order by starttime desc"; ;
            ds = DBUtility.OracleHelper.Query(strSql);
            return ds;
        }
        public int updateAlarm(string id)
        {
            string strSql = "update alarm_info set isticket='1' where alarmnumber='" + id + "' ";
            int result = 0;
            result = DBUtility.OracleHelper.ExecuteSql(strSql);
            return result;
        }
        public int updateFault(string id)
        {
            string strSql = "update fault set isticket='1' where id='" + id + "' ";
            int result = 0;
            result = DBUtility.OracleHelper.ExecuteSql(strSql);
            return result;
        }
     
        public int updateAlarmType(string id)
        {
            string strSql = "update alarm_info set isticket='0' where alarmnumber='" + id + "' ";

            return DBUtility.OracleHelper.ExecuteSql(strSql);
        }
        public int updateFaultType(string id)
        {
            string strSql = "update fault  set isticket='0' where id='" + id + "' ";
            return DBUtility.OracleHelper.ExecuteSql(strSql);
        }
        public int deleteFault(string id)
        {
            string strSql = "delete  fault  where id='"+id+"'";
            return DBUtility.OracleHelper.ExecuteSql(strSql);
        }
        public DataSet  getEtype(string etype)
        {
            string sql = "select RESOURCEID,RESOURCENAME,RESOURCECNNAME from alarm_resource where RESOURCECNNAME='" + etype + "'";
            DataSet ds = new DataSet();
            ds = DBUtility.OracleHelper.Query(sql);
            return ds;

        }
   
   
      
    }
}
